package com.lej.my.compose

import androidx.annotation.DrawableRes
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
import com.lej.core.router.CRouter
import com.lej.core.router.CRouter.Companion.route
import com.lej.dataservice.club.bean.main.home.RoomNftInfo
import com.lej.my.R

class MyPage {
    val url =
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1113%2F052420110515%2F200524110515-2-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1652513446&t=9687003a528d93b328996a5c884b936b"

    @OptIn(ExperimentalFoundationApi::class)
    @Composable
    private fun MyPage() {
        Column(
            modifier = Modifier
                .fillMaxSize()
                .background(Color.Black)
        ) {
            Row {
                Image(
                    painter = painterResource(R.drawable.ic_close_circle_white),
                    null,
                    contentScale = ContentScale.Crop,
                    modifier = Modifier
                        .size(25.dp)
                )
                Text(
                    text = "逛！",
                    color = Color.White,
                    style = MaterialTheme.typography.h6,
                    fontSize = 16.sp,
                    textAlign = TextAlign.Center,
                    modifier = Modifier
                        .padding(start = 10.dp, top = 4.dp)
                )
            }
        }
    }

    @Preview(showBackground = false)
    @Composable
    fun DefaultPreview() {
        itemView(R.drawable.ic_extend, "张三")
    }

    @Composable
    fun ItemPoster(item: RoomNftInfo) {
//        ConstraintLayout(
//            Modifier
//                .padding(4.dp)
//                .background(Color.Black, RoundedCornerShape(8.dp))
//                .padding(bottom = 8.dp)
//        ) {
//            val (ivCover, tvCollect, tvDec, ivStar, tvStar, ivSee, tvSee) = createRefs()
//            Image(
//                painter = painterResource(R.drawable.ic_extend),
//                null,
//                contentScale = ContentScale.Crop,
//                modifier = Modifier
//                    .clickable { CRouter.about.route("id" to item.id.toString()) }
//                    .aspectRatio(169f / 114f, true)
//                    .clip(shape = RoundedCornerShape(8.dp))
//                    .constrainAs(ivCover) {
//                        centerHorizontallyTo(parent)
//                        top.linkTo(parent.top)
//                    })
//
//            Text(text = "${item.show_nft_num}件藏品",
//                color = colorResource(id = R.color.grey_f0f0f0),
//                fontSize = 12.sp,
//                style = MaterialTheme.typography.body1,
//                textAlign = TextAlign.Center,
//                modifier = Modifier
//                    .background(colorResource(R.color.black_50), RoundedCornerShape(2.dp))
//                    .padding(start = 8.dp, end = 8.dp)
//                    .constrainAs(tvCollect) {
//                        start.linkTo(ivCover.start, 8.dp)
//                        bottom.linkTo(ivCover.bottom, 8.dp)
//                    })
//            Text(text = item.title,
//                color = Color.White,
//                style = MaterialTheme.typography.h6,
//                fontSize = 16.sp,
//                textAlign = TextAlign.Center,
//                modifier = Modifier
//                    .padding(top = 4.dp)
//                    .constrainAs(tvDec) {
//                        start.linkTo(parent.start, 4.dp)
//                        top.linkTo(ivCover.bottom)
//                    }
//            )
//            Image(painter = painterResource(R.drawable.icon_home_like),
//                null,
//                modifier = Modifier
//                    .size(15.dp)
//                    .constrainAs(ivStar) {
//                        start.linkTo(parent.start, 4.dp)
//                        top.linkTo(tvDec.bottom, 4.dp)
////                        bottom.linkTo(parent.bottom, 4.dp)
//                    })
//            Text(text = item.like.toString(),
//                color = colorResource(id = R.color.grey_f0f0f0),
//                fontSize = 12.sp,
//                style = MaterialTheme.typography.body1,
//                textAlign = TextAlign.Center,
//                modifier = Modifier
//                    .constrainAs(tvStar) {
//                        start.linkTo(ivStar.end)
//                        centerVerticallyTo(ivStar)
//                    })
//            Image(painter = painterResource(R.drawable.icon_home_see),
//                null,
//                modifier = Modifier
//                    .size(15.dp)
//                    .constrainAs(ivSee) {
//                        centerVerticallyTo(ivStar)
//                        end.linkTo(tvSee.start, 4.dp)
//                    })
//            Text(text = item.pv.toString(),
//                color = colorResource(id = R.color.grey_f0f0f0),
//                fontSize = 12.sp,
//                style = MaterialTheme.typography.body1,
//                textAlign = TextAlign.Center,
//                modifier = Modifier
//                    .constrainAs(tvSee) {
//                        centerVerticallyTo(ivStar)
//                        end.linkTo(parent.end, 4.dp)
//                    })
//        }
    }

    @Composable
    private inline fun itemView(@DrawableRes id: Int, title: String, crossinline action: () -> Unit = {}) {
        Row(
            modifier = Modifier
                .background(Color.Black)
                .clip(shape = RoundedCornerShape(8.dp))
                .clickable { action() }
        ) {
            Image(
                painter = painterResource(id),
                null,
                contentScale = ContentScale.Crop,
                modifier = Modifier
                    .size(25.dp)
            )
            Text(
                text = title,
                color = Color.White,
                style = MaterialTheme.typography.h6,
                fontSize = 16.sp,
                textAlign = TextAlign.Center,
                modifier = Modifier
                    .padding(start = 10.dp, top = 4.dp)
            )
            Image(
                painter = painterResource(id),
                null,
                contentScale = ContentScale.Crop,
                modifier = Modifier
                    .size(25.dp)
            )
        }
    }
}